package com.zcx.qshop.adapter;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.bound.BoundViewHelper;
import com.zcx.qshop.QSApplication;
import com.zcx.qshop.R;
import com.zcx.qshop.entity.Good;

import java.util.List;

/**
 * Created by Administrator on 2015/9/3 0003.
 */
public class GoodAdapter extends BaseAdapter{

    private List<Good> list;

    private LayoutInflater layoutInflater;

    public GoodAdapter(Context context, List<Good> objects) {

        layoutInflater = ((Activity)context).getLayoutInflater();

        list = objects;

    }

    @Override
    public int getCount() {

        return list.size() > 3 ? 3 : list.size();

    }

    @Override
    public Object getItem(int position) {

        return list.get(position);

    }

    @Override
    public long getItemId(int position) {

        return 0;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        Good good = (Good) getItem(position);

        ViewHolder viewHolder = new ViewHolder();

        convertView = BoundViewHelper.boundView(viewHolder, QSApplication.ScaleScreenHelper.loadView((ViewGroup) layoutInflater.inflate(R.layout.item_good, null)));

        viewHolder.img.setImageURI(Uri.parse(good.picurl));

        viewHolder.name.setText(Html.fromHtml(good.title + " " + good.one + " " + good.two));

        viewHolder.price.setText("￥" + good.price + "元/" + good.unit);

        viewHolder.time.setText(good.posttime);

        viewHolder.count.setText("x" + good.number);

        return convertView;

    }

    private class ViewHolder{

        @BoundView(R.id.item_order_img) public SimpleDraweeView img;

        @BoundView(R.id.item_order_name) public TextView name;

        @BoundView(R.id.item_order_price) public TextView price;

        @BoundView(R.id.item_order_time) public TextView time;

        @BoundView(R.id.item_order_count) public TextView count;

    }

}
